package com.fhz.kotlinstest.truepaging

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.fhz.kotlinstest.Data
import com.fhz.kotlinstest.UserRemoteDataSource
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

private const val TAG = "PagingViewModel"
@HiltViewModel
class PagingViewModel @Inject constructor() :ViewModel() {

    private val appStoreRepository = UserRemoteDataSource()
    fun getClassifyData(classifyId: Int): Flow<PagingData<Data>> {
        Log.i(TAG, "getClassifyData: ")
        return Pager(PagingConfig(pageSize = 1, initialLoadSize = 1)) {
            ClassifyNetPagingSource(appStoreRepository)
        }.flow.cachedIn(viewModelScope)
    }


}